package com.flyduck.mall.pms.admin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.flyduck.mall.pms.admin.service.AdminCategoryService;
import com.flyduck.mall.pms.admin.vo.*;
import com.flyduck.ss.common.core.domain.R;
import com.flyduck.mall.common.web.core.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * <p>
 * SysMenuController
 * </p>
 *
 * @author flyduck
 * @since 2024-06-03
 */
@RestController
@RequestMapping("/admin/category")
public class AdminCategoryController extends BaseController {

    @Resource
    private AdminCategoryService sysCategoryService;

    @GetMapping("/getCategoryList")
    public R<List<AdminCategoryRespVO>> getCategoryList(){
        List<AdminCategoryRespVO> adminCategoryRespVOList = sysCategoryService.getCategoryList();
        return R.ok(adminCategoryRespVOList);
    }

    @GetMapping("/getCategoryPage")
    public R<Page<AdminCategoryRespVO>> getCategoryPage(AdminCategoryQueryReqVO sysCategoryQueryReqVO){
        Page<AdminCategoryRespVO> sysCategoryRespVOPage = sysCategoryService.getCategoryPage(getPage(),sysCategoryQueryReqVO);
        return R.ok(sysCategoryRespVOPage);
    }

    @GetMapping("/getCategoryDetailsById/{id}")
    public R<AdminCategoryDetailsRespVO> getCategoryDetailsById(@PathVariable("id") Long id){
        AdminCategoryDetailsRespVO sysCategoryDetailsRespVO = sysCategoryService.getCategoryDetailsById(id);
        return R.ok(sysCategoryDetailsRespVO);
    }

    @PostMapping("/saveCategory")
    public R<Void> saveCategory(@Validated @RequestBody AdminCategorySaveReqVO adminCategorySaveReqVO){
        sysCategoryService.saveCategory(adminCategorySaveReqVO);
        return R.ok();
    }

    @PostMapping("/updateCategory")
    public R<Void> updateCategory(@Validated @RequestBody AdminCategoryUpdateReqVO adminCategoryUpdateReqVO){
        sysCategoryService.updateCategory(adminCategoryUpdateReqVO);
        return R.ok();
    }

    @PostMapping("/batchDeleteByIds")
    public R<Void> batchDeleteByIds(@RequestBody Long[] ids){
        sysCategoryService.batchDeleteByIds(Arrays.asList(ids));
        return R.ok();
    }


}
